package org.charles.zhifou.model.vo;

import cn.hutool.json.JSONUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.charles.zhifou.enums.AppTypeEnum;
import org.charles.zhifou.enums.ScoringStrategyEnum;
import org.charles.zhifou.model.entity.UserAnswer;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 用户答案视图
 *
 * @author charles
 * @version 1.0
 */
@Data
public class UserAnswerVO implements Serializable {

    @Schema(description = "用户答案 id")
    private Long id;

    @Schema(description = "应用 id")
    private Long appId;

    @Schema(description = "应用类型（0-得分类，1-角色测评类）")
    private AppTypeEnum appType;

    @Schema(description = "评分策略（0-自定义，1-AI）")
    private ScoringStrategyEnum scoringStrategy;

    @Schema(description = "用户答案（JSON 数组）")
    private List<String> choices;

    @Schema(description = "评分结果 id")
    private Long resultId;

    @Schema(description = "结果名称，如物流师")
    private String resultName;

    @Schema(description = "结果描述")
    private String resultDesc;

    @Schema(description = "结果图标")
    private String resultPicture;

    @Schema(description = "得分")
    private Integer resultScore;

    @Schema(description = "用户 id")
    private Long userId;

    @Schema(description = "创建时间")
    private Date createTime;

    @Schema(description = "更新时间")
    private Date updateTime;

    @Schema(description = "创建用户信息")
    private UserVO user;

    /**
     * 对象转封装类
     *
     * @param userAnswer
     * @return
     */
    public static UserAnswerVO entityToVo(UserAnswer userAnswer) {
        if (userAnswer == null) {
            return null;
        }

        UserAnswerVO userAnswerVO = new UserAnswerVO();
        BeanUtils.copyProperties(userAnswer, userAnswerVO);
        // 将用户答案转成 List
        userAnswerVO.setChoices(JSONUtil.toList(userAnswer.getChoices(), String.class));

        return userAnswerVO;
    }
}
